# stack.py
# Implementation of a Stack class (Block).
class Stack:
    def __init__(self, max_length = 10):
        print ("Building stack.")
        self.__index    = 0
        self.__elements = [0] * max_length
        
    def push(self, value):
        if (not self.is_full()):
            self.__elements[self.__index] = value
            self.__index               += 1
        
    def pop(self):
        if (not self.is_empty()):
            self.__index -= 1
            element       = self.__elements[self.__index]
            # The value is replaced by it's default.
            self.__elements[self.__index] = 0        
            
            return element
    
    def top(self):
        if (not self.is_empty()):
            return self.__elements[self.__index - 1]
        else:
            return 0
    
    def is_empty(self):
        """
        If the stack is empty this method returns True, otherwise it will return
        False.
        """
        # If index is equals to 0 then the stack is empty.
        return self.__index == 0
    
    def is_full(self):
        """
        If the stack is full this method returns True, otherwise it will return
        False.
        """        
        return self.__index == len(self.__elements)
    
    def show(self):
        print (self.__elements)